package com.jtjrenren.android.taxi.passenger.core.order.cancle;

import android.content.Intent;
import android.widget.CheckBox;
import android.widget.TextView;

import com.jtjrenren.android.taxi.passenger.R;
import com.jtjrenren.android.taxi.passenger.base.BaseActivity;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/2/23.
 */
public class OrderCancleReasonActivity extends BaseActivity {
    public static final String RESULT_DATA = "result_data";

    @BindView(R.id.order_cancle_reason_1_cb)
    CheckBox cb_reason1;
    @BindView(R.id.order_cancle_reason_2_cb)
    CheckBox cb_reason2;
    @BindView(R.id.order_cancle_reason_3_cb)
    CheckBox cb_reason3;
    @BindView(R.id.order_cancle_reason_4_cb)
    CheckBox cb_reason4;


    private int reason = 0;

    @Override
    public int getLayoutId() {
        return R.layout.aty_order_cancle;
    }

    @Override
    public void init() {
        initViews();
    }

    private void initViews() {
        ((TextView) findViewById(R.id.title)).setText(R.string.quxiaodingdan);
    }

    @OnClick(R.id.title_left)
    public void clickBak(){
        finish();
    }

    @OnClick(R.id.order_cancle_reason_1)
    public void clickR1(){
        clearCbs();
        cb_reason1.setChecked(true);
        setResults(1);
    }

    @OnClick(R.id.order_cancle_reason_2)
    public void clickR2(){
        clearCbs();
        cb_reason2.setChecked(true);
        setResults(2);
    }

    @OnClick(R.id.order_cancle_reason_3)
    public void clickR3(){
        clearCbs();
        cb_reason3.setChecked(true);
        setResults(3);
    }

    @OnClick(R.id.order_cancle_reason_4)
    public void clickR4(){
        clearCbs();
        cb_reason4.setChecked(true);
        setResults(4);
    }

    @OnClick(R.id.order_cancle_ok)
    public void clickCommit(){
        setResultsFinish();
    }



    private void setResults(int reasons) {
        reason = reasons;
    }

    private void setResultsFinish() {
        Intent data = new Intent();
        data.putExtra(RESULT_DATA, reason);
        setResult(RESULT_OK, data);
        finish();
    }

    private void clearCbs() {
        cb_reason1.setChecked(false);
        cb_reason2.setChecked(false);
        cb_reason3.setChecked(false);
        cb_reason4.setChecked(false);
    }
}
